<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="expressionFormQueryRef" :model="expressionFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!expressionFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="expressionFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionFormQuerySubmitting" @search="expressionFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="expressionFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="expressionFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="expressionFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionFormQuerySubmitting" @search="expressionFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="公式名称">
              <a-input v-model:value="expressionFormQueryModel.expressionNameAndLike" placeholder="输入公式名称" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="分类">
              <a-input v-model:value="expressionFormQueryModel.expressionTypeAndLike" placeholder="输入分类" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="公式">
              <a-input v-model:value="expressionFormQueryModel.expressionStrAndLike" placeholder="输入公式" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="描述">
              <a-input v-model:value="expressionFormQueryModel.descriptionAndLike" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="expressionFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="expressionFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="expressionFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="expressionFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="expressionAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="expressionListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="expressionListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="expressionDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="expressionListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="expressionDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="expressionTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="expressionDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="expressionDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="expressionListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="expressionListColumns"
        :data-source="expressionListDataSet"
        :loading="expressionListLoading"
        :pagination="false"
        bordered
        :customRow="expressionListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: expressionListSelectedRowKeys, onChange: expressionListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="expressionListDataPage"
        v-model:pageSize="expressionListDataRows"
        :total="expressionListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="expressionListPaginationChange"
        @showSizeChange="expressionListPaginationShowSizeChange"
        v-if="expressionListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!expressionListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(expressionListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="expressionEditDrawerVisible"
      title="编辑计算公式信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="expressionEditDrawerOnClose"
    >
      <a-form ref="expressionFormRef" :model="expressionFormModel" :rules="expressionFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="公式名称" name="expressionName">
              <a-input v-model:value="expressionFormModel.expressionName" placeholder="输入公式名称" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="分类" name="expressionType">
              <a-input v-model:value="expressionFormModel.expressionType" placeholder="输入分类" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="公式" name="expressionStr">
              <a-textarea v-model:value="expressionFormModel.expressionStr" :rows="3" placeholder="输入公式" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="描述" name="description">
              <a-input v-model:value="expressionFormModel.description" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="expressionFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="expressionFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="expressionFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="expressionFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="expressionFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionDetailDrawerVisible"
      title="计算公式详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="公式名称" :span="1">{{ expressionDetailModel.expressionName }}</a-descriptions-item>
          <a-descriptions-item label="分类" :span="1">{{ expressionDetailModel.expressionType }}</a-descriptions-item>
          <a-descriptions-item label="公式" :span="1">{{ expressionDetailModel.expressionStr }}</a-descriptions-item>
          <a-descriptions-item label="描述" :span="1">{{ expressionDetailModel.description }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ expressionDetailModel.weightOrder }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionDataImportDrawerVisible"
      title="计算公式数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="expressionDataImportFileUploadRef" :fileModule="expressionDataImportFileModule" @change="expressionDataImportFileUploadChange" />
          <a-input v-model:value="expressionDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="expressionDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="expressionDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="expressionToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="expressionDataImportFileModule" @change="expressionDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="expressionDataExportDrawerVisible"
      title="计算公式数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="expressionOptionalDataExportFieldList" :selectedDataExportFieldList="expressionSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="expressionToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="expressionToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useExpressionStore } from '/@/store/modules/cn/core/kpis/expressionStore'

import type { Expression } from '/@/model/cn/core/kpis/eo/Expression'
import { toExpression } from '/@/model/cn/core/kpis/eo/Expression'

import type { ExpressionQO } from '/@/model/cn/core/kpis/qo/ExpressionQO'
import { toExpressionQO } from '/@/model/cn/core/kpis/qo/ExpressionQO'

import type { ExpressionVO } from '/@/model/cn/core/kpis/vo/ExpressionVO'
import { toExpressionVO } from '/@/model/cn/core/kpis/vo/ExpressionVO'

@Options({
  name: 'Expression',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useExpressionStore),
  },
})
export default class Expression extends Vue {

  expressionListDataSet: Array<ExpressionVO> = []

  expressionListColumns: Array<object> = [
    {
      title: '公式名称',
      dataIndex: 'expressionName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '分类',
      dataIndex: 'expressionType',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '公式',
      dataIndex: 'expressionStr',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '描述',
      dataIndex: 'description',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  expressionListLoading: boolean = false

  expressionListSelectedRowKeys: string[] = []

  expressionListSelectData: Array<ExpressionVO> = []

  expressionListSelectLength: number = 0

  expressionListSelectCurrentRowIndex: number = -1

  expressionListSelectCurrentRowData: ExpressionVO = toExpressionVO()

  expressionListPaginationVisible: boolean = true

  expressionListDataPage: number = 1

  expressionListDataRows: number = 10

  expressionListDataCount: number = 0

  expressionListRowClickTimeout: number | null = null

  expressionListRowOnChange(selectedRowKeys, selectedRows) {
    this.expressionListSelectedRowKeys = [ ...selectedRowKeys ]
    this.expressionListSelectData = [ ...selectedRows ]
    this.expressionListSelectLength = selectedRows.length
  }

  expressionListCustomRow(record, index) {
    return {
      'class': index === this.expressionListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.expressionListRowClickTimeout) {
          clearTimeout(this.expressionListRowClickTimeout)
          this.expressionListRowClickTimeout = null
        } else {
          this.expressionListRowClickTimeout = setTimeout(() => {
            this.expressionListRowClickTimeout = null
            this.expressionListSelectCurrentRowIndex = index
            this.expressionListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.expressionListSelectedRowKeys ]
            let selectedRows = [ ...this.expressionListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.expressionListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.expressionListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.expressionStore.pkVo(this.$toParam<ExpressionQO>({ id: record.id } as ExpressionQO)).then((res: Res<ExpressionVO>) => {
          if (res.succ) {
            this.expressionDetailModel = { ...res.data[0] }
            this.expressionDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  expressionListGetDataSet() {
    this.expressionListLoading = true
    this.expressionListRowOnChange([], [])
    this.expressionListSelectCurrentRowIndex = -1
    this.expressionListSelectCurrentRowData = toExpressionVO()
    this.expressionStore.pagingVo(this.$toParam<ExpressionQO>({ weightOrderAsc: 'y' } as ExpressionQO, this.expressionListDataPage, this.expressionListDataRows)).then((res: Res<ExpressionVO>) => {
      if (res.succ) {
        this.expressionListPaginationVisible = true
        this.expressionListDataSet = [ ...res.data ]
        this.expressionListDataCount = res.count
        setTimeout(() => { this.expressionListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionListLoading = false }, 500)
    })
  }

  expressionListPaginationChange() {
    this.expressionListGetDataSet()
  }

  expressionListPaginationShowSizeChange() {
    this.expressionListGetDataSet()
  }

  expressionFormQueryVisible: boolean = false

  expressionFormQuerySubmitting: boolean = false

  expressionFormQueryModel: ExpressionQO = toExpressionQO()

  expressionFormQueryUpDown() {
    this.expressionFormQueryVisible = !this.expressionFormQueryVisible
  }

  expressionFormQueryReset() {
    if (this.$refs.expressionFormQueryRef) {
      this.$refs.expressionFormQueryRef.resetFields()
      this.expressionFormQueryModel = toExpressionQO()
    }
  }

  expressionFormQuerySearch() {
    this.expressionFormQuerySubmitting = true
    this.expressionListLoading = true
    this.expressionListRowOnChange([], [])
    this.expressionListSelectCurrentRowIndex = -1
    this.expressionListSelectCurrentRowData = toExpressionVO()
    this.expressionStore.queryVo(this.$toParam<ExpressionQO>(this.$toSearch({ ...this.expressionFormQueryModel }))).then((res: Res<ExpressionVO>) => {
      if (res.succ) {
        this.expressionListPaginationVisible = false
        this.expressionListDataSet = [ ...res.data ]
        this.expressionListDataCount = res.count
        setTimeout(() => { this.expressionFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.expressionListLoading = false }, 500)
    })
  }

  expressionEditDrawerVisible: boolean = false

  expressionFormSaveSubmitting: boolean = false

  expressionFormSaveContinue: boolean = false

  expressionFormModel: Expression = toExpression()

  expressionFormRules: object = {
    // expressionName: [
    //   { type: 'string', required: true, message: '公式名称不能为空！', trigger: ['change', 'blur'] },
    // ],
    // expressionType: [
    //   { type: 'string', required: true, message: '分类不能为空！', trigger: ['change', 'blur'] },
    // ],
    // expressionStr: [
    //   { type: 'string', required: true, message: '公式不能为空！', trigger: ['change', 'blur'] },
    // ],
    // description: [
    //   { type: 'string', required: true, message: '描述不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  expressionFormReset() {
    if (this.$refs.expressionFormRef) {
      this.$refs.expressionFormRef.resetFields()
      this.expressionFormModel = toExpression()
    }
  }

  expressionFormSubmit() {
    this.expressionFormSaveSubmitting = true
    this.$refs.expressionFormRef.validate().then(() => {
      if (this.expressionFormModel.id) {
        this.expressionStore.update(this.$toParam<Expression>(this.expressionFormModel)).then((res: Res<Expression>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionFormReset()
            this.expressionFormSaveSubmitting = false
            if (!this.expressionFormSaveContinue) {
              this.expressionEditDrawerVisible = false
              this.expressionListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.expressionStore.save(this.$toParam<Expression>(this.expressionFormModel)).then((res: Res<Expression>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionFormReset()
            this.expressionFormSaveSubmitting = false
            if (!this.expressionFormSaveContinue) {
              this.expressionEditDrawerVisible = false
              this.expressionListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.expressionFormSaveSubmitting = false }, 3000)
    })
  }

  expressionFormSave() {
    this.expressionFormSaveContinue = false
    this.expressionFormSubmit()
  }

  expressionFormNextAdd() {
    this.expressionFormSaveContinue = true
    this.expressionFormSubmit()
  }

  expressionAdd() {
    if (this.expressionFormModel.id) {
      this.expressionFormReset()
    }
    this.expressionEditDrawerVisible = true
  }

  expressionUpdate() {
    this.expressionStore.pk(this.$toParam<ExpressionQO>({ id: this.expressionListSelectData[0].id } as ExpressionQO)).then((res: Res<Expression>) => {
      if (res.succ) {
        this.expressionFormReset()
        this.expressionFormModel = { ...res.data[0] }
        this.expressionEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionEditDrawerOnClose() {
    if (this.expressionFormSaveContinue) {
      this.expressionFormSaveContinue = false
      this.expressionListGetDataSet()
    }
  }

  expressionDelete() {
    let param: Array<Expression> = []
    this.expressionListSelectData.forEach((eo: ExpressionVO) => {
      param.push({ id: eo.id } as Expression)
    })
    this.expressionStore.removeBatch(this.$toParam<Expression>(param)).then((res: Res<Expression>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.expressionListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionDetailDrawerVisible: boolean = false

  expressionDetailModel: ExpressionVO = toExpressionVO()

  expressionDetailInfo() {
    this.expressionStore.pkVo(this.$toParam<ExpressionQO>({ id: this.expressionListSelectData[0].id } as ExpressionQO)).then((res: Res<ExpressionVO>) => {
      if (res.succ) {
        this.expressionDetailModel = { ...res.data[0] }
        this.expressionDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionDetailUpdate() {
    this.expressionStore.pk(this.$toParam<ExpressionQO>({ id: this.expressionDetailModel.id } as ExpressionQO)).then((res: Res<Expression>) => {
      if (res.succ) {
        this.expressionFormReset()
        this.expressionFormModel = { ...res.data[0] }
        this.expressionDetailDrawerVisible = false
        this.expressionEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  expressionDataImportDrawerVisible: boolean = false

  expressionDataImportFileSelectDrawerVisible: boolean = false

  expressionDataImportFileModule: string = 'dataImport'

  expressionDataImportFileUrl: string = ''

  expressionDataImportSaveSubmitting: boolean = false

  expressionDataImport() {
    this.expressionDataImportDrawerVisible = true
  }

  expressionDataImportFileUploadChange(value) {
    this.expressionDataImportFileUrl = value
  }

  expressionDataImportFileUrlSelectFileClick() {
    this.expressionDataImportFileSelectDrawerVisible = true
  }

  expressionDataImportFileSelectChange(fileUrl) {
    this.expressionDataImportFileUrl = fileUrl
    this.expressionDataImportFileSelectDrawerVisible = false
  }

  expressionToDataImport() {
    this.expressionDataImportSaveSubmitting = true
    this.expressionStore.dataImport(this.$toParam<string>(this.expressionDataImportFileUrl)).then((res: Res<Expression>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.expressionDataImportFileUploadRef.resetFiles()
        this.expressionDataImportFileUrl = ''
        this.expressionDataImportSaveSubmitting = false
        this.expressionDataImportDrawerVisible = false
        this.expressionListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionDataImportSaveSubmitting = false }, 3000)
    })
  }

  expressionDataExportDrawerVisible: boolean = false

  expressionOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'expressionName',
      fieldComment: '公式名称',
    },
    {
      fieldName: 'expressionType',
      fieldComment: '分类',
    },
    {
      fieldName: 'expressionStr',
      fieldComment: '公式',
    },
    {
      fieldName: 'description',
      fieldComment: '描述',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
  ]

  expressionSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  expressionDataExport() {
    this.expressionDataExportDrawerVisible = true
  }

  expressionToDataExport(allData: boolean) {
    this.expressionStore.dataExport(this.$toParam<DataExportAO<ExpressionQO>>(toDataExportAO(this.expressionSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as ExpressionQO : this.$toSearch({ ...this.expressionFormQueryModel }), '计算公式信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.expressionListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
